<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1" name="viewport">
    <title>webrx</title>
</head>
<body>
<script>
    function get() {
        fetch('fetchget.php?id=100&name=李四', {method: 'GET', headers: {token: '1111111111'}}).then(res => res.json()).then(data => {
            console.log(data)
        })
    }

    function fget(url, params, token) {
        if (params) {
            let p = []
            Object.keys(params).forEach(key => p.push(key + '=' + params[key]))
            if (url.search(/\?/) === -1) {
                url += '?' + p.join('&')
            } else {
                url += p.join('&')
            }
        }
        if (token) {
            fetch(url, {method: 'GET', headers: token}).then(res => res.json()).then(data => {
                console.log(data)
            })
        } else {
            fetch(url).then(res => res.json()).then(data => {
                console.log(data)
            })
        }
    }
</script>
<button onclick="get()">fetch get 传参 传token</button>
<button onclick="fget('fetchget.php',{id:999,name:'lisi'},{token:'2222222222'})">fetch fget() 传参 传token</button>
</body>
</html>